function [dx_f,dy_f]=fix_registration_median(dx,dy)

threshold = 15;

dx_f = moving(dx,5,'median');
dy_f = moving(dy,5,'median');

% edge considerations
indices_edges = [1 2 length(dx)-1 length(dx)];
indices_next_good = [3 3 length(dx)-2 length(dx)-2];
% for dx
for ind = 1:length(indices_edges)
    if abs(dx(indices_edges(ind))-dx(indices_next_good(ind))) < threshold
        dx_f(indices_edges(ind)) = dx(indices_edges(ind));
    else
        dx_f(indices_edges(ind)) = dx_f(indices_next_good(ind));
    end
end
% for dy
for ind = 1:length(indices_edges)
    if abs(dy(indices_edges(ind))-dy(indices_next_good(ind))) < threshold
        dy_f(indices_edges(ind)) = dy(indices_edges(ind));
    else
        dy_f(indices_edges(ind)) = dy_f(indices_next_good(ind));
    end
end